1bashThis script searches for lines in the file /bar that do not contain the string foo.grep 'foo' /bar --invert-matchexternal toolsgrep
2bashThis demonstrates using grep to filter lines based on a regular expression.grep "^foo.*bar$" file.txtexternal toolsgrepregex filter (regular expression filter)
3bashSearch for the string foo in the file /bar and display one line of context around each match. This demonstrates using grep with the --context option to show surrounding lines for better context in search results.grep 'foo' /bar --context 1external toolsgrep
4bashThis script searches for the string foo in the directory /bar recursively, following symbolic links.grep 'foo' /bar --dereference-recursiveexternal toolsgrep
5bashCount the number of lines in file.txt that match the regex pattern ^foo.*bar$. The -c option in grep is used to print the count of matching lines instead of the lines themselves. This demonstrates how to count occurrences of a specific pattern in a file.grep -c "^foo.*bar$" file.txtexternal toolsgrep
6bashSearch for the string Foo in the file /bar using grep with case-insensitive matching. This demonstrates how to find text in a file while ignoring case sensitivity.grep 'Foo' /bar --ignore-caseexternal toolsgrep
7bashThis script searches for lines in file.txt that start with foo and end with bar, then excludes any lines containing baz.grep "^foo.*bar$" file.txt | grep -v "baz"external toolsgrep
8bashThis script searches for the string foo in the directory /bar and lists the files that contain matches.grep 'foo' /bar --files-with-matchesexternal toolsgrep
9bashThis script searches for the exact line containing foo in the file /bar using grep with the --line-regexp option.grep 'foo' /bar --line-regexpexternal toolsgrep
10bashThis script searches for the string foo in the file /bar and displays the line numbers where matches occur.grep 'foo' /bar --line-numberexternal toolsgrep
11bashThis demonstrates using egrep to recursively search for lines containing either foo or bar within the /baz directory.egrep 'foo|bar' /baz -Rexternal toolsgrepregex filter (regular expression filter)multi-pattern search with recursion
12bashThis demonstrates using grep to search for a specific string in a file and conditionally print a message if the string is found.if grep -q 'foo' ~/.bash_history; then echo "You appear to have typed 'foo' in the past" fiexternal toolsgrepstring search
13bashThis demonstrates using fgrep to search for a fixed string in a file.fgrep "foobar" file.txtexternal toolsgrepfixed string search
14bashThis script searches for the string foo in the file /bar.txt.grep 'foo' /bar.txtexternal toolsgrep
15bashSearch for files in /bar that do not contain the string foo using grep with the --files-without-match option. This demonstrates finding files without a specific pattern.grep 'foo' /bar --files-without-matchexternal toolsgrep
16bashThis script searches for the string foo recursively in the directory /bar using the grep command.grep 'foo' /bar --recursiveexternal toolsgrep
17bashSearch for the string foo in the file /bar and count the number of occurrences using the grep command with the --count option. This demonstrates how to find and count specific text in a file.grep 'foo' /bar --countexternal toolsgrep
18bashThis script searches for the string foo in the file /bar and highlights the matches with color.grep 'foo' /bar --colourexternal toolsgrep
19bashThis demonstrates using grep with extended regular expressions to search for patterns in a file, though the -R option is incorrectly applied.grep --extended-regexp|-E 'foo|bar' /baz -Rexternal toolsgrepregex filter (regular expression filter)extended regular expressions
20bashThis demonstrates advanced usage of the grep command, including recursive search, line number inclusion, and binary file exclusion.grep -r "^foo.*bar$" someDir/ # recursively `grep` grep -n "^foo.*bar$" file.txt # give line numbers grep -rI "^foo.*bar$" someDir/ # recursively `grep`, but ignore binary filesexternal toolsgreprecursive search